<template>
  <view class=""  :style="{marginTop}">
	  <!-- 证件提示 -->
	  <view>
		<l-notice-bar v-if="noticeList.length > 0 && noticeList[0] != ''" type="error" :list="noticeList" />
	  </view>
  	<view class="card padding-30 flex-row" style="width: 100%;flex-direction: column;position: relative;" @click="toDetail">
  	  <view style="width: 100%;flex-direction: row;">
		  <view class="avatar">
		    <image class="avatar" :src="item.avatar || defaultAvatar" mode="aspectFill" />
		  </view>
		  <view class="flex-item flex-column margin-left-30 justify-between relative" style="justify-content: center;">
		    <view>
		      <view class="flex-row align-center">
		        <text class="text-32 color-t1 text-bold margin-right-12">{{ item.nickname }}</text>
		      </view>
		      <view class="margin-top-10 flex-row">
		        <text class="text-24 color-t3">{{ item.phone }}</text>
		      </view>
		    </view>
		    <view class="tags flex-row">
		      <l-tag plain border-width="0" height="44rpx" :type="examineStatusTag.type" :text="examineStatusTag.text" />
		    </view>
		  </view>
	  </view>
	  <!--  -->
	  <view class="flex-row justify-end" style="width: 100%;justify-content: flex-start;align-items: center;flex-wrap: wrap;">
	  	<!-- <view v-if="waringUpBtn.length > 0" @click.stop="goUpPage(item.type)" v-for="(item,index) in waringUpBtn" class="margin-right-16 margin-top-16 update-certificate" style="background: linear-gradient(90deg, #E8C9A2 0%, #D9A96A 100%);color: #865825FF;">
	  		{{item.name}}
	  	 </view>
		<view v-if="errorUpBtn.length > 0" @click.stop="goUpPage(item.type)" v-for="(item,index) in errorUpBtn" class="margin-right-16 margin-top-16 update-certificate">
	  		{{item.name}}
	  	 </view> -->
	    <tui-button class="margin-right-16 margin-top-16" v-if="auth.includes('driver_set_status')" width="94rpx" height="54rpx" border-radius="8rpx" :size="26" plain type="gray" text="状态" @click="setStatus" />
	    <template v-if="item.status !== 3">
	      <view v-if="!type && (item.examineStatus === 0 || item.examineStatus === 3) && auth.includes('driver_submit_review')" class="margin-right-16 margin-top-16">
	        <tui-button width="94rpx" height="54rpx" border-radius="8rpx" :size="26" plain type="gray" text="审核" @click="jump(2)" />
	      </view>
	      <view v-if="auth.includes('driver_edit')" class="margin-right-16 margin-top-16">
	        <tui-button width="94rpx" height="54rpx" border-radius="8rpx" :size="26" plain type="gray" text="编辑" @click="jump('')" />
	      </view>
	    </template>
	    <view v-if="auth.includes('driver_delete')" class="margin-right-16 margin-top-16">
	      <tui-button width="94rpx" height="54rpx" border-radius="8rpx" :size="26" plain type="gray" text="删除" @click="deleteDriver" />
	    </view>
	  </view> 
  	</view>
  </view>
</template>

<script>
import { mapGetters } from 'vuex'
import { jump } from '@/common/util'
export default {
  name: 'DriverItem',
  props: {
    type: {
      type: Number,
      default: 0
    },
    item: {
      type: Object,
      default: () => {}
    },
    marginTop: {
      type: String,
      default: '30rpx'
    }
  },
  data() {
    return {
		errorUpBtn:[], // 到期预警
		waringUpBtn:[],// 即将到期
		waringUpBtnType:['身份证更新','驾驶证更新','从业资格证更新','行驶证更新','道路运输证更新','上传三年无重大事故证明'],
		errorUpBtnType:['身份证更新','驾驶证更新','从业资格证更新','行驶证更新','道路运输证更新','上传三年无重大事故证明'],
		noticeType:'waring',
		noticeTypeArray:['waring','error'],
		noticeList:[],
        src: 'https://tbb-file.oss-cn-shenzhen.aliyuncs.com/tbb_admin_app/icon/',
        defaultAvatar: 'https://tbb-file.oss-cn-shenzhen.aliyuncs.com/tbb_admin_app/static/default_avatar.png'
    }
  },
  computed: {
    examineStatusTag() {
      switch (this.item.examineStatus) {
        case 0:
          return {
            type: 'error',
            text: '未审核'
          }
        case 1:
          return {
            type: 'warning',
            text: '审核中'
          }
        case 2:
          return {
            type: 'success',
            text: '审核通过'
          }
        case 3:
          return {
            type: 'error',
            text: '审核已驳回'
          }
      }
      return {
        type: 'error',
        text: '未审核'
      }
    },
    ...mapGetters({
      auth: 'auth'
    })
  },
  watch: {
	  item: {
		  handler(newVal) {
			  this.noticeList = []
			  this.errorUpBtn = [];// 到期预警
			  		this.waringUpBtn = [];// 即将到期
			  if(this.item.certWarningList && this.item.certWarningList.length > 0){
			  				  for(let i of this.item.certWarningList){
			  					  //  即将到期的
			  					  if(i.status == 1) {
			  						  switch (i.certificationType){
			  						  	case 0:
			  								this.waringUpBtn.push({
			  									name:'身份证更新',
			  									type: 0
			  								})
			  						  		break;
			  							case 1:
			  								this.waringUpBtn.push({
			  									name:'驾驶证更新',
			  									type: 1
			  								})
			  								break;
			  							case 2:
			  								this.waringUpBtn.push({
			  									name:'从业资格证更新',
			  									type: 2
			  								})
			  								break;
			  							case 3:
			  								this.waringUpBtn.push({
			  									name:'行驶证更新',
			  									type: 3
			  								})
			  								break;
			  							case 4:
			  								this.waringUpBtn.push({
			  									name:'道路运输证更新',
			  									type: 4
			  								})
			  								break;
			  							case 5:
			  								this.waringUpBtn.push({
			  									name:'上传三年无重大事故证明',
			  									type: 5
			  								})
			  								break;
			  						  	default:
			  						  		break;
			  						  }
			  					  }else if(i.status == 2 || i.status == 6 || i.status == 5) {
			  						  switch (i.certificationType){
			  						  	case 0:
			  								this.errorUpBtn.push({
			  									name:i.status==6 ? '身份证未上传' : '身份证更新',
			  									type: 0,
			  										status: i.status
			  								})
			  						  		break;
			  							case 1:
			  								this.errorUpBtn.push({
			  									name: i.status==6 ? '驾驶证未上传' : '驾驶证更新',
			  									type: 1,
			  										status: i.status
			  								})
			  								break;
			  							case 2:
			  								this.errorUpBtn.push({
			  									name: i.status==6 ? '从业资格证未上传' : '从业资格证更新',
			  									type: 2,
			  										status: i.status
			  								})
			  								break;
			  							case 3:
			  								this.errorUpBtn.push({
			  									name: i.status==6 ? '行驶证未上传' : '行驶证更新',
			  									type: 3,
			  										status: i.status
			  								})
			  								break;
			  							case 4:
			  								this.errorUpBtn.push({
			  									name: i.status==6 ? '道路运输证未上传' : '道路运输证更新',
			  									type: 4,
			  										status: i.status
			  								})
			  								break;
			  							case 5:
			  								this.errorUpBtn.push({
			  									name: i.status==6 ? '三年无重大事故证明未上传' : '三年无重大事故证明更新',
			  									type: 5,
			  										status: i.status
			  								})
			  								break;
			  						  	default:
			  						  		break;
			  						  }
			  					  }
			  				  }
			  					  let newNoticeList = '该司机'
			  					  if(this.waringUpBtn && this.waringUpBtn.length > 0) {
			  						  for(let value of this.waringUpBtn){
			  							  newNoticeList = newNoticeList + value.name + '即将到期,'
			  						  }
			  					  }
			  					  if(this.errorUpBtn && this.errorUpBtn.length > 0) {
			  						  for(let value of this.errorUpBtn){
			  							  if(value.status == 6){
			  								  newNoticeList = newNoticeList + value.name + ','
			  							  }else {
			  								  newNoticeList = newNoticeList + value.name + '已到期,'
			  							  }
			  						  }
			  					  }
			  					  newNoticeList = newNoticeList + '请登录车企PC端进行'
			  					  var reg1 = new RegExp("更新","g"); // 加'g'，删除字符串里所有的"a"
			  					  var a1 = newNoticeList.replace(reg1,"");
			  					  newNoticeList = a1 + '更新!'
			  					  if((this.errorUpBtn && this.errorUpBtn.length > 0) || (this.waringUpBtn && this.waringUpBtn.length > 0)){
			  						  this.noticeList.push(newNoticeList)
			  					  }
			  				  console.log(this.errorUpBtn,this.waringUpBtn)
			  }else {
			  				  
			  }
		  }
	  },
	  deep: true
  },
  created() {
	  this.errorUpBtn = [];// 到期预警
		this.waringUpBtn = [];// 即将到期
	  if(this.item.certWarningList && this.item.certWarningList.length > 0){
	  				  for(let i of this.item.certWarningList){
	  					  //  即将到期的
	  					  if(i.status == 1) {
	  						  switch (i.certificationType){
	  						  	case 0:
	  								this.waringUpBtn.push({
	  									name:'身份证更新',
	  									type: 0
	  								})
	  						  		break;
	  							case 1:
	  								this.waringUpBtn.push({
	  									name:'驾驶证更新',
	  									type: 1
	  								})
	  								break;
	  							case 2:
	  								this.waringUpBtn.push({
	  									name:'从业资格证更新',
	  									type: 2
	  								})
	  								break;
	  							case 3:
	  								this.waringUpBtn.push({
	  									name:'行驶证更新',
	  									type: 3
	  								})
	  								break;
	  							case 4:
	  								this.waringUpBtn.push({
	  									name:'道路运输证更新',
	  									type: 4
	  								})
	  								break;
	  							case 5:
	  								this.waringUpBtn.push({
	  									name:'上传三年无重大事故证明',
	  									type: 5
	  								})
	  								break;
	  						  	default:
	  						  		break;
	  						  }
	  					  }else if(i.status == 2 || i.status == 6 || i.status == 5) {
	  						  switch (i.certificationType){
	  						  	case 0:
	  								this.errorUpBtn.push({
	  									name:i.status==6 ? '身份证未上传' : '身份证更新',
	  									type: 0,
										status: i.status
	  								})
	  						  		break;
	  							case 1:
	  								this.errorUpBtn.push({
	  									name: i.status==6 ? '驾驶证未上传' : '驾驶证更新',
	  									type: 1,
										status: i.status
	  								})
	  								break;
	  							case 2:
	  								this.errorUpBtn.push({
	  									name: i.status==6 ? '从业资格证未上传' : '从业资格证更新',
	  									type: 2,
										status: i.status
	  								})
	  								break;
	  							case 3:
	  								this.errorUpBtn.push({
	  									name: i.status==6 ? '行驶证未上传' : '行驶证更新',
	  									type: 3,
										status: i.status
	  								})
	  								break;
	  							case 4:
	  								this.errorUpBtn.push({
	  									name: i.status==6 ? '道路运输证未上传' : '道路运输证更新',
	  									type: 4,
										status: i.status
	  								})
	  								break;
	  							case 5:
	  								this.errorUpBtn.push({
	  									name: i.status==6 ? '三年无重大事故证明未上传' : '三年无重大事故证明更新',
	  									type: 5,
										status: i.status
	  								})
	  								break;
	  						  	default:
	  						  		break;
	  						  }
	  					  }
	  				  }
					  let newNoticeList = '该司机'
					  if(this.waringUpBtn && this.waringUpBtn.length > 0) {
						  for(let value of this.waringUpBtn){
							  newNoticeList = newNoticeList + value.name + '即将到期,'
						  }
					  }
					  if(this.errorUpBtn && this.errorUpBtn.length > 0) {
						  for(let value of this.errorUpBtn){
							  if(value.status == 6){
								  newNoticeList = newNoticeList + value.name + ','
							  }else {
								  newNoticeList = newNoticeList + value.name + '已到期,'
							  }
						  }
					  }
					  newNoticeList = newNoticeList + '请登录车企PC端进行'
					  var reg1 = new RegExp("更新","g"); // 加'g'，删除字符串里所有的"a"
					  var a1 = newNoticeList.replace(reg1,"");
					  newNoticeList = a1 + '更新!'
					  if((this.errorUpBtn && this.errorUpBtn.length > 0) || (this.waringUpBtn && this.waringUpBtn.length > 0)){
						  this.noticeList.push(newNoticeList)
					  }
	  				  console.log(this.errorUpBtn,this.waringUpBtn)
	  }else {
	  				  
	  }
  },
  methods: {
    toDetail() {
      jump('/driver/driver-detail/driver-detail?id=' + this.item.userId)
    },
    jump(e) {
      let url = '/driver/add-driver/add-driver?id=' + this.item.userId
      if (e) url += '&type=' + e
      jump(url)
    },
	goUpPage(data){
		console.log(data)
		console.log(this.item)
		uni.navigateTo({
			url:'/pages/uploaddocuments/uploaddocuments?type=' + Number(data) + '&id=' + this.item.driverId
		})
	},
    setStatus() {
      this.$emit('setStatus', {
        userId: this.item.userId,
        status: this.item.status
      })
    },
    deleteDriver() {
      this.$emit('del', this.item.userId)
    }
  }
}
</script>

<style scoped lang="scss">
@include setMargin(right,12);

.card{
  border-radius:20rpx;
  border:2rpx solid $color-border;
  position: relative;
}
.prompt-icon {
	width: 28rpx;
	height: 28rpx;
	margin-right: 20rpx;
}
.prompt-dueto {
	  width: 90%;
	  font-size: 24rpx;
	  font-family: PingFang SC-Regular, PingFang SC;
	  font-weight: 400;
	  padding: 26rpx 0;
	  display: flex;
	  align-items: center;
	  justify-content: center;
	  color: #E4433A;
	  line-height: 24rpx;
	  border-radius: 18rpx 18rpx 0 0;
	  margin: 0 auto;
	  background: rgba(232, 118, 112, .2);
	  flex-direction: row;
  }
  .prompt{
	  flex-direction: row;
  	  width: 90%;
  	  font-size: 24rpx;
  	  font-family: PingFang SC-Regular, PingFang SC;
  	  font-weight: 400;
  	  padding: 26rpx 0;
  	  display: flex;
  	  align-items: center;
  	  justify-content: center;
  	  color: #865825FF;
  	  line-height: 24rpx;
  	  border-radius: 18rpx 18rpx 0 0;
  	  margin: 0 auto;
  	  background: rgba(232, 201, 162, .5);
    }
	.update-certificate {
		padding: 10rpx;
		background: linear-gradient(90deg, #E87670 0%, #E4433A 100%);
		border-radius: 6rpx;
		font-size: 22rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 30rpx;
	}
	.update-certificate-cv {
		padding: 10rpx;
		background: linear-gradient(90deg, #E8C9A2 0%, #D9A96A 100%);
		border-radius: 6rpx;
		font-size: 22rpx;
		font-family: PingFang SC-Regular, PingFang SC;
		font-weight: 400;
		color: #FFFFFF;
		line-height: 30rpx;
	}
.avatar{
  width: 120rpx;
  height: 120rpx;
  border-radius: 100%;
}
.sex{
  width:32rpx;
  height:32rpx;
}
.tags{
  @include position(absolute,0,0);
  position: absolute;
  right: 0;
  top: 0;
  width: fit-content;
}
</style>
